using System;
using System.Data;
using System.Data.OleDb;
using System.Collections;
using System.Configuration;
using System.Runtime.InteropServices;

//Using PCS's namespaces 
using PCSComUtils.DataAccess;
using PCSComUtils.PCSExc;
using PCSComUtils.Common;

namespace PCSComProduction.ValueAddTransact.DS
{
	public class PRO_OutsideProcessingDetailDS//
	{
		#region Declaration, Constructor

		private const string THIS = "PCSComProduction.ValueAddTransact.DS.PRO_OutsideProcessingDetailDS";

		public PRO_OutsideProcessingDetailDS()
		{
		}
	
		#endregion Declaration, Constructor

		#region Update Data Methods
		
		//**************************************************************************              
		///    <Description>
		///       This method uses to add data to PRO_OutsideProcessingDetail
		///    </Description>
		///    <Inputs>
		///        PRO_OutsideProcessingDetailVO       
		///    </Inputs>
		///    <Outputs>
		///       newly inserted primarkey value
		///    </Outputs>
		///    <Returns>
		///       void
		///    </Returns>
		///    <Authors>
		///       HungLa
		///    </Authors>
		///    <History>
		///       Tuesday, May 31, 2005
		///    </History>
		///    <Notes>
		///    </Notes>
		//**************************************************************************


		public void Add(object pobjObjectVO)
		{
			const string METHOD_NAME = THIS + ".Add()";
			 
			OleDbConnection oconPCS =null;
			OleDbCommand ocmdPCS =null;
			try
			{
				PRO_OutsideProcessingDetailVO objObject = (PRO_OutsideProcessingDetailVO)pobjObjectVO;
				
				string strSql = "INSERT INTO PRO_OutsideProcessingDetail("
					+ PRO_OutsideProcessingDetailTable.OUTSIDEPROCESSINGMASTERID_FLD + ","
					+ PRO_OutsideProcessingDetailTable.WORKORDERDETAILID_FLD + ","
					+ PRO_OutsideProcessingDetailTable.INVOICENO_FLD + ","
					+ PRO_OutsideProcessingDetailTable.INVOICEAMOUNT_FLD + ","
					+ PRO_OutsideProcessingDetailTable.QUANTITY_FLD + ","
					+ PRO_OutsideProcessingDetailTable.COMPLETEPERCENT_FLD + ","
					+ PRO_OutsideProcessingDetailTable.WORKORDERMASTERID_FLD + ","
					+ PRO_OutsideProcessingDetailTable.VENDORID_FLD + ","
					+ PRO_OutsideProcessingDetailTable.PARTYLOCATIONID_FLD + ","
					+ PRO_OutsideProcessingDetailTable.WOROUTINGID_FLD + ","
					+ PRO_OutsideProcessingDetailTable.COMPLETED_FLD + ")"
					+ " VALUES(?,?,?,?,?,?,?,?,?,?,?)";

				
				oconPCS = new OleDbConnection(Utils.Instance.OleDbConnectionString);
				ocmdPCS = new OleDbCommand(strSql, oconPCS);			

				ocmdPCS.Parameters.Add(new OleDbParameter(PRO_OutsideProcessingDetailTable.OUTSIDEPROCESSINGMASTERID_FLD, OleDbType.Integer));
				ocmdPCS.Parameters[PRO_OutsideProcessingDetailTable.OUTSIDEPROCESSINGMASTERID_FLD].Value = objObject.OutsideProcessingMasterID;

				ocmdPCS.Parameters.Add(new OleDbParameter(PRO_OutsideProcessingDetailTable.WORKORDERDETAILID_FLD, OleDbType.Integer));
				ocmdPCS.Parameters[PRO_OutsideProcessingDetailTable.WORKORDERDETAILID_FLD].Value = objObject.WorkOrderDetailID;

				ocmdPCS.Parameters.Add(new OleDbParameter(PRO_OutsideProcessingDetailTable.INVOICENO_FLD, OleDbType.VarWChar));
				ocmdPCS.Parameters[PRO_OutsideProcessingDetailTable.INVOICENO_FLD].Value = objObject.InvoiceNo.Trim();

				ocmdPCS.Parameters.Add(new OleDbParameter(PRO_OutsideProcessingDetailTable.INVOICEAMOUNT_FLD, OleDbType.Decimal));
				ocmdPCS.Parameters[PRO_OutsideProcessingDetailTable.INVOICEAMOUNT_FLD].Value = objObject.InvoiceAmount;

				ocmdPCS.Parameters.Add(new OleDbParameter(PRO_OutsideProcessingDetailTable.QUANTITY_FLD, OleDbType.Decimal));
				ocmdPCS.Parameters[PRO_OutsideProcessingDetailTable.QUANTITY_FLD].Value = objObject.Quantity;

				ocmdPCS.Parameters.Add(new OleDbParameter(PRO_OutsideProcessingDetailTable.COMPLETEPERCENT_FLD, OleDbType.Decimal));
				ocmdPCS.Parameters[PRO_OutsideProcessingDetailTable.COMPLETEPERCENT_FLD].Value = objObject.CompletePercent;

				ocmdPCS.Parameters.Add(new OleDbParameter(PRO_OutsideProcessingDetailTable.WORKORDERMASTERID_FLD, OleDbType.Integer));
				ocmdPCS.Parameters[PRO_OutsideProcessingDetailTable.WORKORDERMASTERID_FLD].Value = objObject.WorkOrderMasterID;

				ocmdPCS.Parameters.Add(new OleDbParameter(PRO_OutsideProcessingDetailTable.VENDORID_FLD, OleDbType.Integer));
				ocmdPCS.Parameters[PRO_OutsideProcessingDetailTable.VENDORID_FLD].Value = objObject.VendorID;

				ocmdPCS.Parameters.Add(new OleDbParameter(PRO_OutsideProcessingDetailTable.PARTYLOCATIONID_FLD, OleDbType.Integer));
				ocmdPCS.Parameters[PRO_OutsideProcessingDetailTable.PARTYLOCATIONID_FLD].Value = objObject.PartyLocationID;

				ocmdPCS.Parameters.Add(new OleDbParameter(PRO_OutsideProcessingDetailTable.WOROUTINGID_FLD, OleDbType.Integer));
				ocmdPCS.Parameters[PRO_OutsideProcessingDetailTable.WOROUTINGID_FLD].Value = objObject.WORoutingID;

				ocmdPCS.Parameters.Add(new OleDbParameter(PRO_OutsideProcessingDetailTable.COMPLETED_FLD, OleDbType.Boolean));
				ocmdPCS.Parameters[PRO_OutsideProcessingDetailTable.COMPLETED_FLD].Value = objObject.Completed;
								
				ocmdPCS.Connection.Open();
				ocmdPCS.ExecuteNonQuery();	

			}
			catch(OleDbException ex)
			{
				if (ex.Errors[1].NativeError == ErrorCode.SQLDUPLICATE_KEYCODE)
				{																   
					throw new PCSDBException(ErrorCode.DUPLICATE_KEY, METHOD_NAME, ex);				
				}
				else
				{
					throw new PCSDBException(ErrorCode.ERROR_DB, METHOD_NAME,ex);
				}
			}
			catch(InvalidOperationException ex)
			{
				throw new PCSDBException(ErrorCode.ERROR_DB, METHOD_NAME,ex);
			}
			catch (Exception ex) 
			{
				throw new PCSDBException(ErrorCode.OTHER_ERROR, METHOD_NAME, ex);
			}
			finally 
			{
				if (oconPCS!=null) 
				{
					if (oconPCS.State != ConnectionState.Closed) 
					{
						oconPCS.Close();
					}
				}
			}
		}

		//**************************************************************************              
		///    <Description>
		///       This method uses to update data to PRO_OutsideProcessingDetail
		///    </Description>
		///    <Inputs>
		///       PRO_OutsideProcessingDetailVO       
		///    </Inputs>
		///    <Outputs>
		///       
		///    </Outputs>
		///    <Returns>
		///       
		///    </Returns>
		///    <Authors>
		///       HungLa
		///    </Authors>
		///    <History>
		///       09-Dec-2004
		///    </History>
		///    <Notes>
		///    </Notes>
		//**************************************************************************
			
		public void Update(object pobjObjecVO)
		{
			const string METHOD_NAME = THIS + ".Update()";

			PRO_OutsideProcessingDetailVO objObject = (PRO_OutsideProcessingDetailVO)pobjObjecVO;			

			//prepare value for parameters
			OleDbConnection oconPCS =null;
			OleDbCommand ocmdPCS = null;
			try 
			{
				string strSql = "UPDATE PRO_OutsideProcessingDetail SET "
					+ PRO_OutsideProcessingDetailTable.OUTSIDEPROCESSINGMASTERID_FLD + "=   ?" + ","
					+ PRO_OutsideProcessingDetailTable.WORKORDERDETAILID_FLD + "=   ?" + ","
					+ PRO_OutsideProcessingDetailTable.INVOICENO_FLD + "=   ?" + ","
					+ PRO_OutsideProcessingDetailTable.INVOICEAMOUNT_FLD + "=   ?" + ","
					+ PRO_OutsideProcessingDetailTable.QUANTITY_FLD + "=   ?" + ","
					+ PRO_OutsideProcessingDetailTable.COMPLETEPERCENT_FLD + "=   ?" + ","
					+ PRO_OutsideProcessingDetailTable.WORKORDERMASTERID_FLD + "=   ?" + ","
					+ PRO_OutsideProcessingDetailTable.VENDORID_FLD + "=   ?" + ","
					+ PRO_OutsideProcessingDetailTable.PARTYLOCATIONID_FLD + "=   ?" + ","
					+ PRO_OutsideProcessingDetailTable.WOROUTINGID_FLD + "=   ?" + ","
					+ PRO_OutsideProcessingDetailTable.COMPLETED_FLD + "=  ?"
					+" WHERE " + PRO_OutsideProcessingDetailTable.OUTSIDEPRCESSINGDETAILID_FLD + "= ?";
				

				
				oconPCS = new OleDbConnection(Utils.Instance.OleDbConnectionString);
				ocmdPCS = new OleDbCommand(strSql, oconPCS);
				
				ocmdPCS.Parameters.Add(new OleDbParameter(PRO_OutsideProcessingDetailTable.OUTSIDEPROCESSINGMASTERID_FLD, OleDbType.Integer));
				ocmdPCS.Parameters[PRO_OutsideProcessingDetailTable.OUTSIDEPROCESSINGMASTERID_FLD].Value = objObject.OutsideProcessingMasterID;

				ocmdPCS.Parameters.Add(new OleDbParameter(PRO_OutsideProcessingDetailTable.WORKORDERDETAILID_FLD, OleDbType.Integer));
				ocmdPCS.Parameters[PRO_OutsideProcessingDetailTable.WORKORDERDETAILID_FLD].Value = objObject.WorkOrderDetailID;

				ocmdPCS.Parameters.Add(new OleDbParameter(PRO_OutsideProcessingDetailTable.INVOICENO_FLD, OleDbType.VarWChar));
				ocmdPCS.Parameters[PRO_OutsideProcessingDetailTable.INVOICENO_FLD].Value = objObject.InvoiceNo;

				ocmdPCS.Parameters.Add(new OleDbParameter(PRO_OutsideProcessingDetailTable.INVOICEAMOUNT_FLD, OleDbType.Decimal));
				ocmdPCS.Parameters[PRO_OutsideProcessingDetailTable.INVOICEAMOUNT_FLD].Value = objObject.InvoiceAmount;

				ocmdPCS.Parameters.Add(new OleDbParameter(PRO_OutsideProcessingDetailTable.QUANTITY_FLD, OleDbType.Decimal));
				ocmdPCS.Parameters[PRO_OutsideProcessingDetailTable.QUANTITY_FLD].Value = objObject.Quantity;

				ocmdPCS.Parameters.Add(new OleDbParameter(PRO_OutsideProcessingDetailTable.COMPLETEPERCENT_FLD, OleDbType.Decimal));
				ocmdPCS.Parameters[PRO_OutsideProcessingDetailTable.COMPLETEPERCENT_FLD].Value = objObject.CompletePercent;

				ocmdPCS.Parameters.Add(new OleDbParameter(PRO_OutsideProcessingDetailTable.WORKORDERMASTERID_FLD, OleDbType.Integer));
				ocmdPCS.Parameters[PRO_OutsideProcessingDetailTable.WORKORDERMASTERID_FLD].Value = objObject.WorkOrderMasterID;

				ocmdPCS.Parameters.Add(new OleDbParameter(PRO_OutsideProcessingDetailTable.VENDORID_FLD, OleDbType.Integer));
				ocmdPCS.Parameters[PRO_OutsideProcessingDetailTable.VENDORID_FLD].Value = objObject.VendorID;

				ocmdPCS.Parameters.Add(new OleDbParameter(PRO_OutsideProcessingDetailTable.PARTYLOCATIONID_FLD, OleDbType.Integer));
				ocmdPCS.Parameters[PRO_OutsideProcessingDetailTable.PARTYLOCATIONID_FLD].Value = objObject.PartyLocationID;

				ocmdPCS.Parameters.Add(new OleDbParameter(PRO_OutsideProcessingDetailTable.WOROUTINGID_FLD, OleDbType.Integer));
				ocmdPCS.Parameters[PRO_OutsideProcessingDetailTable.WOROUTINGID_FLD].Value = objObject.WORoutingID;

				ocmdPCS.Parameters.Add(new OleDbParameter(PRO_OutsideProcessingDetailTable.COMPLETED_FLD, OleDbType.Boolean));
				ocmdPCS.Parameters[PRO_OutsideProcessingDetailTable.COMPLETED_FLD].Value = objObject.Completed;

				ocmdPCS.Parameters.Add(new OleDbParameter(PRO_OutsideProcessingDetailTable.OUTSIDEPRCESSINGDETAILID_FLD, OleDbType.Integer));
				ocmdPCS.Parameters[PRO_OutsideProcessingDetailTable.OUTSIDEPRCESSINGDETAILID_FLD].Value = objObject.OutsidePrcessingDetailID;
				
				ocmdPCS.Connection.Open();
				ocmdPCS.ExecuteNonQuery();	
			}
			catch(OleDbException ex)
			{
				if (ex.Errors[1].NativeError == ErrorCode.SQLDUPLICATE_KEYCODE)
				{
																   
					throw new PCSDBException(ErrorCode.DUPLICATE_KEY, METHOD_NAME, ex);				
				}
				else
				{
					throw new PCSDBException(ErrorCode.ERROR_DB, METHOD_NAME,ex);
				}
			}
			catch(InvalidOperationException ex)
			{
				throw new PCSDBException(ErrorCode.ERROR_DB, METHOD_NAME,ex);
			}
			catch (Exception ex) 
			{
				throw new PCSDBException(ErrorCode.OTHER_ERROR, METHOD_NAME, ex);
			}
			finally 
			{
				if (oconPCS!=null) 
				{
					if (oconPCS.State != ConnectionState.Closed) 
					{
						oconPCS.Close();
					}
				}
			}
		}
		
		//**************************************************************************              
		///    <Description>
		///       This method uses to update a DataSet
		///    </Description>
		///    <Inputs>
		///        DataSet       
		///    </Inputs>
		///    <Outputs>
		///       
		///    </Outputs>
		///    <Returns>
		///       
		///    </Returns>
		///    <Authors>
		///       HungLa
		///    </Authors>
		///    <History>
		///       Tuesday, May 31, 2005
		///    </History>
		///    <Notes>
		///    </Notes>
		//**************************************************************************
		
		public void UpdateDataSet(DataSet pdstData)
		{
			const string METHOD_NAME = THIS + ".UpdateDataSet()";			
			OleDbConnection oconPCS =null;
			OleDbCommandBuilder odcbPCS ;
			OleDbDataAdapter odadPCS = new OleDbDataAdapter();
			try
			{
				string strSql =	"SELECT "
					+ PRO_OutsideProcessingDetailTable.OUTSIDEPRCESSINGDETAILID_FLD + ","
					+ PRO_OutsideProcessingDetailTable.OUTSIDEPROCESSINGMASTERID_FLD + ","
					+ PRO_OutsideProcessingDetailTable.WORKORDERDETAILID_FLD + ","
					+ PRO_OutsideProcessingDetailTable.INVOICENO_FLD + ","
					+ PRO_OutsideProcessingDetailTable.INVOICEAMOUNT_FLD + ","
					+ PRO_OutsideProcessingDetailTable.QUANTITY_FLD + ","
					+ PRO_OutsideProcessingDetailTable.COMPLETEPERCENT_FLD + ","
					+ PRO_OutsideProcessingDetailTable.WORKORDERMASTERID_FLD + ","
					+ PRO_OutsideProcessingDetailTable.VENDORID_FLD + ","
					+ PRO_OutsideProcessingDetailTable.PARTYLOCATIONID_FLD + ","
					+ PRO_OutsideProcessingDetailTable.WOROUTINGID_FLD + ","
					+ PRO_OutsideProcessingDetailTable.COMPLETED_FLD 
					+ "  FROM " + PRO_OutsideProcessingDetailTable.TABLE_NAME;

				
				oconPCS = new OleDbConnection(Utils.Instance.OleDbConnectionString);
				odadPCS.SelectCommand = new OleDbCommand(strSql, oconPCS);
				odcbPCS = new OleDbCommandBuilder(odadPCS);
				pdstData.EnforceConstraints = false;
				odadPCS.Update(pdstData, PRO_OutsideProcessingDetailTable.TABLE_NAME);

			}
			catch(OleDbException ex)
			{
				if (ex.Errors[1].NativeError == ErrorCode.SQLDUPLICATE_KEYCODE)
				{
																   
					throw new PCSDBException(ErrorCode.DUPLICATE_KEY, METHOD_NAME, ex);				
				}
				else if (ex.Errors[1].NativeError == ErrorCode.SQLCASCADE_PREVENT_KEYCODE)
				{

					throw new PCSDBException(ErrorCode.CASCADE_DELETE_PREVENT, METHOD_NAME, ex);				
				}
				
				else
				{
					throw new PCSDBException(ErrorCode.ERROR_DB, METHOD_NAME,ex);
				}
			}
			catch(InvalidOperationException ex)
			{
				throw new PCSDBException(ErrorCode.ERROR_DB, METHOD_NAME,ex);
			}
			catch (Exception ex) 
			{
				throw new PCSDBException(ErrorCode.OTHER_ERROR, METHOD_NAME, ex);
			}
			finally 
			{
				if (oconPCS!=null) 
				{
					if (oconPCS.State != ConnectionState.Closed) 
					{
						oconPCS.Close();
					}
				}
			}
		}
		
		//**************************************************************************              
		///    <Description>
		///       This method uses to delete data from PRO_OutsideProcessingDetail
		///    </Description>
		///    <Inputs>
		///        ID       
		///    </Inputs>
		///    <Outputs>
		///       void
		///    </Outputs>
		///    <Returns>
		///       
		///    </Returns>
		///    <Authors>
		///       HungLa
		///    </Authors>
		///    <History>
		///       09-Dec-2004
		///    </History>
		///    <Notes>
		///    </Notes>
		//**************************************************************************

		public void Delete(int pintID)
		{
			const string METHOD_NAME = THIS + ".Delete()";

			string strSql = "DELETE " + PRO_OutsideProcessingDetailTable.TABLE_NAME + " WHERE  " + "OutsidePrcessingDetailID" + "=" + pintID.ToString();
			OleDbConnection oconPCS = null;
			OleDbCommand ocmdPCS = null;
			try
			{
				
				oconPCS = new OleDbConnection(Utils.Instance.OleDbConnectionString);
				ocmdPCS = new OleDbCommand(strSql, oconPCS);

				ocmdPCS.Connection.Open();
				ocmdPCS.ExecuteNonQuery();	
				ocmdPCS = null;
			}
			catch(OleDbException ex)
			{
				if (ex.Errors[1].NativeError == ErrorCode.SQLCASCADE_PREVENT_KEYCODE)
				{																   
					throw new PCSDBException(ErrorCode.CASCADE_DELETE_PREVENT, METHOD_NAME, ex);				
				}
				else
				{
					throw new PCSDBException(ErrorCode.ERROR_DB, METHOD_NAME,ex);
				}
			}
			catch (Exception ex) 
			{
				throw new PCSDBException(ErrorCode.OTHER_ERROR, METHOD_NAME, ex);
			}
			finally 
			{
				if (oconPCS != null) 
				{
					if (oconPCS.State != ConnectionState.Closed) 
					{
						oconPCS.Close();
					}
				}
			}
		}	

		#endregion Update Data Methods

		#region Retrieve Data Methods
		
		//**************************************************************************              
		///    <Description>
		///       This method uses to get data from PRO_OutsideProcessingDetail
		///    </Description>
		///    <Inputs>
		///        ID       
		///    </Inputs>
		///    <Outputs>
		///       PRO_OutsideProcessingDetailVO
		///    </Outputs>
		///    <Returns>
		///       PRO_OutsideProcessingDetailVO
		///    </Returns>
		///    <Authors>
		///       HungLa
		///    </Authors>
		///    <History>
		///       Tuesday, May 31, 2005
		///    </History>
		///    <Notes>
		///    </Notes>
		//**************************************************************************

		public object GetObjectVO(int pintID)
		{
			const string METHOD_NAME = THIS + ".GetObjectVO()";
			DataSet dstPCS = new DataSet();
			
			OleDbDataReader odrPCS = null;
			OleDbConnection oconPCS = null;
			OleDbCommand ocmdPCS = null;
			try 
			{
				string strSql = "SELECT "
						+ PRO_OutsideProcessingDetailTable.OUTSIDEPRCESSINGDETAILID_FLD + ","
						+ PRO_OutsideProcessingDetailTable.OUTSIDEPROCESSINGMASTERID_FLD + ","
						+ PRO_OutsideProcessingDetailTable.WORKORDERDETAILID_FLD + ","
						+ PRO_OutsideProcessingDetailTable.INVOICENO_FLD + ","
						+ PRO_OutsideProcessingDetailTable.INVOICEAMOUNT_FLD + ","
						+ PRO_OutsideProcessingDetailTable.QUANTITY_FLD + ","
						+ PRO_OutsideProcessingDetailTable.COMPLETEPERCENT_FLD + ","
						+ PRO_OutsideProcessingDetailTable.WORKORDERMASTERID_FLD + ","
						+ PRO_OutsideProcessingDetailTable.VENDORID_FLD + ","
						+ PRO_OutsideProcessingDetailTable.PARTYLOCATIONID_FLD + ","
						+ PRO_OutsideProcessingDetailTable.WOROUTINGID_FLD + ","
						+ PRO_OutsideProcessingDetailTable.COMPLETED_FLD
						+ " FROM " + PRO_OutsideProcessingDetailTable.TABLE_NAME
						+ " WHERE " + PRO_OutsideProcessingDetailTable.OUTSIDEPRCESSINGDETAILID_FLD + "=" + pintID;

				
				oconPCS = new OleDbConnection(Utils.Instance.OleDbConnectionString);
				ocmdPCS = new OleDbCommand(strSql, oconPCS);

				ocmdPCS.Connection.Open();
				odrPCS = ocmdPCS.ExecuteReader();

				PRO_OutsideProcessingDetailVO objObject = new PRO_OutsideProcessingDetailVO();

				if(odrPCS.Read())
				{ 
					objObject.OutsidePrcessingDetailID = int.Parse(odrPCS[PRO_OutsideProcessingDetailTable.OUTSIDEPRCESSINGDETAILID_FLD].ToString().Trim());
					objObject.OutsideProcessingMasterID = int.Parse(odrPCS[PRO_OutsideProcessingDetailTable.OUTSIDEPROCESSINGMASTERID_FLD].ToString().Trim());
					objObject.WorkOrderDetailID = int.Parse(odrPCS[PRO_OutsideProcessingDetailTable.WORKORDERDETAILID_FLD].ToString().Trim());
					objObject.InvoiceNo = odrPCS[PRO_OutsideProcessingDetailTable.INVOICENO_FLD].ToString().Trim();
					objObject.InvoiceAmount = Decimal.Parse(odrPCS[PRO_OutsideProcessingDetailTable.INVOICEAMOUNT_FLD].ToString().Trim());
					objObject.Quantity = Decimal.Parse(odrPCS[PRO_OutsideProcessingDetailTable.QUANTITY_FLD].ToString().Trim());
					objObject.CompletePercent = Decimal.Parse(odrPCS[PRO_OutsideProcessingDetailTable.COMPLETEPERCENT_FLD].ToString().Trim());
					objObject.WorkOrderMasterID = int.Parse(odrPCS[PRO_OutsideProcessingDetailTable.WORKORDERMASTERID_FLD].ToString().Trim());
					objObject.VendorID = int.Parse(odrPCS[PRO_OutsideProcessingDetailTable.VENDORID_FLD].ToString().Trim());
					objObject.PartyLocationID = int.Parse(odrPCS[PRO_OutsideProcessingDetailTable.PARTYLOCATIONID_FLD].ToString().Trim());
					objObject.WORoutingID = int.Parse(odrPCS[PRO_OutsideProcessingDetailTable.WOROUTINGID_FLD].ToString().Trim());
					objObject.Completed = bool.Parse(odrPCS[PRO_OutsideProcessingDetailTable.COMPLETED_FLD].ToString().Trim());
				}
				return objObject;					
			}
			catch(OleDbException ex)
			{			
				throw new PCSDBException(ErrorCode.ERROR_DB, METHOD_NAME,ex);
			}
			catch (Exception ex) 
			{
				throw new PCSDBException(ErrorCode.OTHER_ERROR, METHOD_NAME, ex);
			}
			finally 
			{
				if (oconPCS!=null) 
				{
					if (oconPCS.State != ConnectionState.Closed) 
					{
						oconPCS.Close();
					}
				}
			}
		}
	
		//**************************************************************************              
		///    <Description>
		///       This method uses to get all data from PRO_OutsideProcessingDetail
		///    </Description>
		///    <Inputs>
		///               
		///    </Inputs>
		///    <Outputs>
		///       DataSet
		///    </Outputs>
		///    <Returns>
		///       DataSet
		///    </Returns>
		///    <Authors>
		///       HungLa
		///    </Authors>
		///    <History>
		///       Tuesday, May 31, 2005
		///    </History>
		///    <Notes>
		///    </Notes>
		//**************************************************************************

		public DataSet List()
		{
			const string METHOD_NAME = THIS + ".List()";
			DataSet dstPCS = new DataSet();
			
			OleDbConnection oconPCS =null;
			OleDbCommand ocmdPCS = null;
			try 
			{
				string strSql = "SELECT "
						+ PRO_OutsideProcessingDetailTable.OUTSIDEPRCESSINGDETAILID_FLD + ","
						+ PRO_OutsideProcessingDetailTable.OUTSIDEPROCESSINGMASTERID_FLD + ","
						+ PRO_OutsideProcessingDetailTable.WORKORDERDETAILID_FLD + ","
						+ PRO_OutsideProcessingDetailTable.INVOICENO_FLD + ","
						+ PRO_OutsideProcessingDetailTable.INVOICEAMOUNT_FLD + ","
						+ PRO_OutsideProcessingDetailTable.QUANTITY_FLD + ","
						+ PRO_OutsideProcessingDetailTable.COMPLETEPERCENT_FLD + ","
						+ PRO_OutsideProcessingDetailTable.WORKORDERMASTERID_FLD + ","
						+ PRO_OutsideProcessingDetailTable.VENDORID_FLD + ","
						+ PRO_OutsideProcessingDetailTable.PARTYLOCATIONID_FLD + ","
						+ PRO_OutsideProcessingDetailTable.WOROUTINGID_FLD + ","
						+ PRO_OutsideProcessingDetailTable.COMPLETED_FLD
						+ " FROM " + PRO_OutsideProcessingDetailTable.TABLE_NAME;

				
				oconPCS = new OleDbConnection(Utils.Instance.OleDbConnectionString);
				ocmdPCS = new OleDbCommand(strSql, oconPCS);
				ocmdPCS.Connection.Open();
				
				OleDbDataAdapter odadPCS = new OleDbDataAdapter(ocmdPCS);
				odadPCS.Fill(dstPCS,PRO_OutsideProcessingDetailTable.TABLE_NAME);

				return dstPCS;
			}
			catch(OleDbException ex)
			{
   				throw new PCSDBException(ErrorCode.ERROR_DB, METHOD_NAME,ex);
			}			
			catch (Exception ex) 
			{
				throw new PCSDBException(ErrorCode.OTHER_ERROR, METHOD_NAME, ex);
			}
			finally 
			{
				if (oconPCS!=null) 
				{
					if (oconPCS.State != ConnectionState.Closed) 
					{
						oconPCS.Close();
					}
				}
			}
		}	
		

		/// <summary>
		/// List all information in detail table to load to grid on form
		/// </summary>
		/// <param name="pintMasterID"></param>
		/// <returns></returns>
		public DataTable GetDetailByMaster(int pintMasterID)
		{
			const string METHOD_NAME = THIS + ".GetDetailByMaster()";
			
			DataSet dstPCS = new DataSet();
			
			OleDbConnection oconPCS =null;
			OleDbCommand ocmdPCS = null;

			try 
			{
				string strSql = "SELECT "
					+ PRO_OutsideProcessingDetailTable.TABLE_NAME + "." + PRO_OutsideProcessingDetailTable.OUTSIDEPRCESSINGDETAILID_FLD + ", "
					+ PRO_WorkOrderMasterTable.TABLE_NAME + "." + PRO_WorkOrderMasterTable.WORKORDERMASTERID_FLD + ", " 
					+ PRO_WorkOrderMasterTable.TABLE_NAME + "." + PRO_WorkOrderMasterTable.WORKORDERNO_FLD + ", "
					+ PRO_WorkOrderDetailTable.TABLE_NAME + "." + PRO_WorkOrderDetailTable.LINE_FLD + " as " + PRO_WorkOrderDetailTable.TABLE_NAME + PRO_WorkOrderDetailTable.LINE_FLD + ", "
					+ PRO_WORoutingTable.TABLE_NAME + "." + PRO_WORoutingTable.STEP_FLD + " as " + PRO_WORoutingTable.TABLE_NAME + PRO_WORoutingTable.STEP_FLD + ", "					
					+ MST_PartyTable.TABLE_NAME + "." + MST_PartyTable.CODE_FLD + " as " + MST_PartyTable.TABLE_NAME +  MST_PartyTable.CODE_FLD + ", "
					+ MST_PartyLocationTable.TABLE_NAME + "." + MST_PartyLocationTable.CODE_FLD  + " as " + MST_PartyLocationTable.TABLE_NAME + MST_PartyLocationTable.CODE_FLD +  ", "
					+ PRO_OutsideProcessingDetailTable.TABLE_NAME + "." + PRO_OutsideProcessingDetailTable.INVOICENO_FLD + ", "
					+ PRO_OutsideProcessingDetailTable.TABLE_NAME + "." + PRO_OutsideProcessingDetailTable.INVOICEAMOUNT_FLD + ", "
					+ PRO_OutsideProcessingDetailTable.TABLE_NAME + "." + PRO_OutsideProcessingDetailTable.QUANTITY_FLD + ", "
					+ PRO_OutsideProcessingDetailTable.TABLE_NAME + "." + PRO_OutsideProcessingDetailTable.COMPLETEPERCENT_FLD + ", " 
					+ PRO_OutsideProcessingDetailTable.TABLE_NAME + "." + PRO_OutsideProcessingDetailTable.COMPLETED_FLD + ", "
					+ PRO_OutsideProcessingDetailTable.TABLE_NAME + "." + PRO_OutsideProcessingDetailTable.VENDORID_FLD + ", "
					+ PRO_OutsideProcessingDetailTable.TABLE_NAME + "." + PRO_OutsideProcessingDetailTable.PARTYLOCATIONID_FLD + ", "
					+ PRO_OutsideProcessingDetailTable.TABLE_NAME + "." + PRO_OutsideProcessingDetailTable.WOROUTINGID_FLD + ", "	
					+ PRO_OutsideProcessingDetailTable.TABLE_NAME + "." + PRO_OutsideProcessingDetailTable.OUTSIDEPROCESSINGMASTERID_FLD + ", "
					+ PRO_OutsideProcessingDetailTable.TABLE_NAME + "." + PRO_OutsideProcessingDetailTable.WORKORDERDETAILID_FLD
					+ " FROM " + PRO_OutsideProcessingDetailTable.TABLE_NAME					
					+ " INNER JOIN " + PRO_WORoutingTable.TABLE_NAME 
					+ " ON " + PRO_OutsideProcessingDetailTable.TABLE_NAME + "." + PRO_OutsideProcessingDetailTable.WOROUTINGID_FLD + "=" + PRO_WORoutingTable.TABLE_NAME + "." + PRO_WORoutingTable.WOROUTINGID_FLD
					+ " INNER JOIN " + MST_PartyTable.TABLE_NAME 
					+ " ON " + PRO_OutsideProcessingDetailTable.TABLE_NAME + "." + PRO_OutsideProcessingDetailTable.VENDORID_FLD + "=" +  MST_PartyTable.TABLE_NAME + "." + MST_PartyTable.PARTYID_FLD
					+ " INNER JOIN " + MST_PartyLocationTable.TABLE_NAME 
					+ " ON " + PRO_OutsideProcessingDetailTable.TABLE_NAME +  "." + PRO_OutsideProcessingDetailTable.PARTYLOCATIONID_FLD + "=" + MST_PartyLocationTable.TABLE_NAME + "." + MST_PartyLocationTable.PARTYLOCATIONID_FLD
					+ " INNER JOIN " + PRO_WorkOrderDetailTable.TABLE_NAME 
					+ " ON " + PRO_OutsideProcessingDetailTable.TABLE_NAME + "." + PRO_OutsideProcessingDetailTable.WORKORDERDETAILID_FLD + "=" + PRO_WorkOrderDetailTable.TABLE_NAME + "." + PRO_WorkOrderDetailTable.WORKORDERDETAILID_FLD					
					+ " INNER JOIN " + PRO_WorkOrderMasterTable.TABLE_NAME 
					+ " ON " + PRO_OutsideProcessingDetailTable.TABLE_NAME + "." + PRO_OutsideProcessingDetailTable.WORKORDERMASTERID_FLD + "=" + PRO_WorkOrderMasterTable.TABLE_NAME + "." + PRO_WorkOrderMasterTable.WORKORDERMASTERID_FLD
					+ " WHERE " + PRO_OutsideProcessingDetailTable.TABLE_NAME + "." + PRO_OutsideProcessingDetailTable.OUTSIDEPROCESSINGMASTERID_FLD + "=" + pintMasterID.ToString();
				
				
				oconPCS = new OleDbConnection(Utils.Instance.OleDbConnectionString);
				ocmdPCS = new OleDbCommand(strSql, oconPCS);
				ocmdPCS.Connection.Open();
				
				OleDbDataAdapter odadPCS = new OleDbDataAdapter(ocmdPCS);
				odadPCS.Fill(dstPCS, PRO_OutsideProcessingDetailTable.TABLE_NAME);

				return dstPCS.Tables[0];
			}
			catch(OleDbException ex)
			{
				throw new PCSDBException(ErrorCode.ERROR_DB, METHOD_NAME,ex);
			}			
			catch (Exception ex) 
			{
				throw new PCSDBException(ErrorCode.OTHER_ERROR, METHOD_NAME, ex);
			}
			finally 
			{
				if (oconPCS!=null) 
				{
					if (oconPCS.State != ConnectionState.Closed) 
					{
						oconPCS.Close();
						oconPCS = null;
					}
				}
			}
		}

		#endregion Retrieve Data Methods
	}
}